use axum::Json;
use serde_json::Value;
use sea_orm::EntityTrait;
use crate::query;

use super::del::{ many, one };

// 删除单个
pub async fn by_id_del_file<E:EntityTrait>(entity:E, value:u32, file:Vec<&str>, mongo:bool) -> Result<Json<Value>, Json<Value>>{ 
    one(entity, "id", Some(value), None, Some(file), mongo).await
}
pub async fn by_id<E:EntityTrait>(entity:E, value:u32) -> Result<Json<Value>, Json<Value>>{ 
    by_id_del_file(entity, value, Vec::new(), false).await
}
// 删除多个
pub async fn by_ids_del_file<E:EntityTrait>(entity:E, value:&str, file:Vec<&str>, mongo:bool) -> Result<Json<Value>, Json<Value>>{
    let ids = query::utils::vec_u32_str_(&value, "")?;
    if ids.len() == 1 {
        by_id_del_file(entity, ids[0], file, mongo).await
    }else{
        many(entity, "id",  Some(ids), None, Some(file), mongo).await
    }
}
pub async fn by_ids<E:EntityTrait>(entity:E, value:&str) -> Result<Json<Value>, Json<Value>>{
    by_ids_del_file(entity, value, Vec::new(), false).await
}